package com.ym.pms.service.impl;

import com.ym.pms.dao.NoticeDao;
import com.ym.pms.model.Notice;
import com.ym.pms.service.HomeNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeNoticeServiceImpl implements HomeNoticeService {

    @Autowired
    NoticeDao dao;

    @Override
    public Map<String, List<Map<String, String>>> getAllNotice() {
        Map<String, List<Map<String, String>>> HomeNotice = new HashMap<>();
        List<Map<String, String>> list1 = new ArrayList<>();
        List<Map<String, String>> list2 = new ArrayList<>();
        List<Notice> notices = dao.findAll();
        int i = 0;
        for (Notice notice : notices) {
            Map<String,String> map = new HashMap<>();
            Map<String,String> map1 = new HashMap<>();
            map.put("key",String.valueOf(i));
            map.put("iconType",notice.getIcontype());
            map.put("content",notice.getOp());
            list1.add(map);
            map1.put("key",String.valueOf(i));
            map1.put("title",notice.getTitle());
            map1.put("content",notice.getContent());
            list2.add(map1);
            i++;
        }
        HomeNotice.put("menuList",list1);
        HomeNotice.put("noticeList",list2);
        return HomeNotice;
    }

    @Override
    public void add(Notice notice) {
        dao.insert(notice);
    }

    @Override
    public void update(Notice notice) {
        dao.insertSelective(notice);
    }

    @Override
    public void delete(Integer id) {
        dao.deleteByPrimaryKey(id);
    }
}
